package krow.dev.gunpobus.control.http;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

/**
 * BitmapCache
 * @author syuan
 * @since 2013. 10. 4.	 
*/
public class BitmapCache extends LruCache<String, Bitmap> implements ImageCache{

	
	public BitmapCache() {
		this(getDefaultSize());
	}
	
	public BitmapCache(int size) {
		super(size);
	}

	
	/**
	 * @Method getDefaultSize
	 * @author syuan
	 * @since 2013. 10. 4.
	 * @return cacheSize	 
	*/
	public static int getDefaultSize(){
		int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
		int cacheSize = maxMemory / 8;
		return cacheSize;
	}
	
	@Override
	public Bitmap getBitmap(String url) {
		return get(url);
	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		put(url, bitmap);
	}
	
	@Override
	protected int sizeOf(String key, Bitmap value) {
		return value.getRowBytes() * value.getHeight() / 1024;
	}
}
